<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="">
			<div style="margin-left: 10px;">
				<div style="margin:20px 0px 35px 80px">
					<label for="jobcode">员工编号:</label> 
					<select type="text" style="width: 200px; height: 28px;" class="ui-input" 
					name="username" id="userType">
						<s:forEach items="${sessionScope.userList}" var="user">
							<option value="${user.usercode }">${user.usercode }</option>
						</s:forEach>
					</select><br/>
				</div>
				<div style="margin:20px 0px 35px 80px">
					<label for="jobcode">公司全称:</label> 
					<select type="text" style="width: 200px; height: 28px;" class="ui-input" 
					name="tradename" id="tradeType">
						<s:forEach items="${sessionScope.companyList}" var="company">
							<option value="${company.companyname}">${company.companyname}</option>
						</s:forEach>
					</select><br/>
				</div>
				<div style="margin:20px 0px 35px 80px">
					<label for="jobcode">员工角色:</label> 
					<select type="text" style="width: 200px; height: 28px;" class="ui-input" 
					name="rolename" id="cotegoryType">
						<s:forEach items="${sessionScope.roleList}" var="role">
							<option value="${role.rolename}">${role.rolename }</option>
						</s:forEach>
					</select>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript">
			var api=frameElement.api;
			var operate=api.data.operate;
			var rowid=api.data.rowid;
			var rowdata=api.data.rowdata;
			var CallBack=api.data.callback;
			$(function(){
				initPopBtns();
				if(operate=="edit"){
					$("#cotegoryType").val(rowdata.type);
				}
			})
			//初始化按钮
			function initPopBtns() {
				var btnname = "add" == operate ? ["添加", "关闭"] : ["确定", "取消"];
				api.button({
					id: "confirm",
					name: btnname[0],
					focus: true,
					callback: function(e) {
						var rolename = $("#cotegoryType option:selected").val();
						var usercode = $("#userType option:selected").val();
						var companyname = $("#tradeType option:selected").val();
						if(operate=="add"){
							$.ajax({
								url : '/addUserRole',
								type : 'POST',
								dataType : "json",
								data: {
									"rolename":rolename,
									"usercode":usercode,
									"companyname":companyname
								},
								async : false,
								success : function(data) {
									if(data.status==200){
										parent.Public.tips({
											content: "添加角色名成功"
										})
										CallBack();
									}else{
										parent.Public.tips({
											type:1,
											content: "添加角色名失败:"+data.msg
										})
									}
								}
							});
						}else{
							$.ajax({
								url:encodeURI("category/edit"),
								type:"POST",
								data:{
									"id":rowid,
									"type":name
								},
								async : false,//同步,坑爹啊。。
								success:function(data){
									if(data.status==200){
										parent.Public.tips({
											content: "修改商品类别成功"
										})
										CallBack();
									}else{
										parent.Public.tips({
											type:1,
											content: "修改商品类别失败:"+data.msg
										})
									}		
								}
							});
						}
					}
				}, {
					id: "cancel",
					name: btnname[1]
				})
			}

</script>
</body>
</html>